
function onDeleteNews(url, newsId, newsImage, resp)
{
	var isOK = -1;
	
	if(!confirm('Are you sure you want to delete the news with Id:' + newsId))
	{
		return false;
	}
	
	new Ajax.Request(url, 
	{
	  method: 'post',
	  asynchronous: false,
	  parameters:'act=delnews&id=' + newsId + '&news_image=' + newsImage,
	  onSuccess: function(transport) 
  		{
			var response = transport.responseText || "";
				var pos=response.indexOf('<!');
				content=response.substring(0,pos);

			obj = content.evalJSON();

    		if(obj == null)
    		{
    			$(resp).innerHTML = 'Something wrong! Reponsed string is: ' + response;
    		}
    		
    		isOK = obj.code;
		
    		$(resp).update(obj.message);
		}
	});

	$(resp).style.display = 'inherit';
	Fat.fade_element(resp, null, 1500, null, null);

	if(isOK == 0)
	{
		rowID = 'news-' + newsId;
		Fat.fade_element(rowID, null, 1000, "#f22", null);
		setTimeout("$(rowID).remove()", 1000);
	}				
}

function onAddNews(frmID, msgDiv, listtable,news_content)
{
	var newId = '';
	$(news_content).value = tinyMCE.getContent(news_content);
	$(frmID).request(
		{
			asynchronous: false,
			parameters: $(frmID).serialize(true),
	  		onComplete: function(transport)
	  		{ 
			  	var response = transport.responseText || "";
		    	
		    	$(msgDiv).innerHTML = '';

		    	if(response != "")
		    	{
		    		//alert(response);
		    		obj = response.evalJSON();
		    		
		    		if(obj == null)
		    		{
		    			$(msgDiv).update('Something wrong! Reponsed string is: ' + response);
		    		}
		    		
			    	if(msgDiv != null)
				    	$(msgDiv).update(obj.message);
				    
				    if(obj.ID > -1)
					{
					    if(listtable != null && $(listtable) != null)
					    {
							sClassName = 'newrow';
						
							str = '<tr id="news-' + obj.ID + '" class="newrow">';
							str +=	'<th scope="row" style="text-align: center">' + obj.ID + '</th>';
							str +=	'<td style="text-align: center">' + '<img src="../includes/thumb.php?src='+obj.news_image+'" alt="" border="0" />' + '</td>';
							str +=	'	<td>' + obj.news_title + '</td>';
							str +=	'	<td style="text-align: center"><a href="?mod=manage&sub1=news&act=editnews&id=' + obj.ID + '" '; 
							str +=	'			class="edit">Edit</td>';
							str +=	'	<td style="text-align: center"><a onclick="onDeleteNews(\'?mod=manage&sub1=news\', \'' + obj.ID  + '\', \'' + obj.news_image  + '\', \'ajaxResponse1\')"'; 
							str +=	'			class="delete">Delete</td>';
							str +=	'</tr>';
							
							$(listtable).innerHTML += str;
								
							newId = 'news-' + obj.ID;
						    	
					    }
		    		}
		    	}
	  		}
		});

	$(msgDiv).style.display = 'block';
	Fat.fade_element(msgDiv, null, 1500, null, null);
	if(newId != '')
	{
		Fat.fade_element(newId);
		$(frmID).reset();
	}
	//revent submit page
	return false;
}


function onEditNews(frmID, msgDiv,news_content)
{
	var newId = '';
	var status = null;
	var ret = null;
	var message = null;
	$(news_content).value = tinyMCE.getContent(news_content);
	$(frmID).request(
		{
			asynchronous: false,
			parameters: $(frmID).serialize(true),
	  		onComplete: function(transport)
	  		{ 
			  	var response = transport.responseText || "";
			  	var pos=response.indexOf('<!');
				content=response.substring(1,pos);
				//alert(content);
		    	$(msgDiv).innerHTML = '';
		    	if(content != "")
		    	{
		    		obj = content.evalJSON();
		    		if(obj == null)
		    		{
		    			$(msgDiv).update('Something wrong! Reponsed string is: ' + content);
		    		}
		    		
			    	if(msgDiv != null)
				    	$(msgDiv).update(obj.message);
					if(obj.ID==0)
					{
						ret =1;	
						message = obj.msg;
					}
					
		    	}
	  		}
		});
	if(ret==1)
	{
		document.location = '?mod=manage&sub1=news&message=' + message;
	}
	else
	{
	$(msgDiv).style.display = 'block';
	Fat.fade_element(msgDiv, null, 1500, null, null);
	//revent submit page
	}
	return false;
}